import 'package:clean_app/asset/color.dart';
import 'package:clean_app/asset/modal.dart';
import 'package:clean_app/asset/textstyle.dart';
import 'package:clean_app/components/miw.dart';
import 'package:clean_app/components/os_svg.dart';
import 'package:clean_app/interface/mid_interface.dart';
import 'package:clean_app/pages/login/login.dart';
import 'package:clean_app/pages/uploaded_tasks/uploaded_tasks.dart';
import 'package:clean_app/provider/login_provider.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class Me extends StatefulWidget {
  const Me({super.key});

  @override
  State<Me> createState() => _MeState();
}

class _MeState extends State<Me> {
  @override
  Widget build(BuildContext context) {
    bool isLogin = isLogined(context);
    return Scaffold(
      appBar: AppBar(
        toolbarHeight: 0,
        backgroundColor: isLogin ? os_grey : os_white,
      ),
      backgroundColor: isLogin ? os_grey : os_white,
      body: ListView(
        children: [
          if (isLogin) Container(height: 40),
          if (isLogin)
            os_svg(
              path: "lib/img/pic.svg",
              size: 100,
            ),
          if (isLogin) Container(height: 40),
          if (isLogin) MeInfo(),
          if (!isLogin) Login(),
        ],
      ),
    );
  }
}

class MeInfo extends StatefulWidget {
  const MeInfo({super.key});

  @override
  State<MeInfo> createState() => _MeInfoState();
}

class _MeInfoState extends State<MeInfo> {
  @override
  Widget build(BuildContext context) {
    var _p = Provider.of<UserProvider>(context);
    return Column(
      children: [
        Text(
          _p.info['username'],
          style: XSTextStyle(
            context: context,
            color: os_light_light_dark_card,
            fontSize: 16.5,
            fontWeight: FontWeight.bold,
          ),
        ),
        Container(height: 7.5),
        GestureDetector(
          onTap: () {
            showModal(
              context: context,
              title: "请确认",
              cont: "是否要退出登录？",
              confirmTxt: "确认退出",
              confirm: () {
                _p.logout();
              },
            );
          },
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                "您当前身份为：${_p.info['user_type']}",
                style: XSTextStyle(
                  context: context,
                  color: os_deep_grey,
                  fontSize: 14.5,
                  fontWeight: FontWeight.normal,
                ),
              ),
              Container(width: 5),
              Icon(
                Icons.logout,
                color: os_deep_grey,
                size: 16,
              ),
            ],
          ),
        ),
        Container(height: 50),
        Container(
          margin: EdgeInsets.only(left: 15, right: 15),
          child: myInkWell(
            color: os_white,
            radius: 100,
            tap: () {
              Navigator.of(context).pushNamed("/draft_page");
            },
            widget: Container(
              padding:
                  EdgeInsets.only(left: 22.5, right: 20, top: 14, bottom: 14),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      Container(
                        decoration: BoxDecoration(
                          color: os_wonderful_color_opa[3],
                          borderRadius: BorderRadius.circular(100),
                        ),
                        padding: EdgeInsets.all(7.5),
                        child: Icon(
                          Icons.cloud_upload_outlined,
                          color: os_wonderful_color[3],
                        ),
                      ),
                      Container(width: 12.5),
                      Text(
                        "待上传任务",
                        style: XSTextStyle(
                          context: context,
                          color: os_black,
                          fontSize: 15,
                          fontWeight: FontWeight.normal,
                        ),
                      ),
                    ],
                  ),
                  Icon(
                    Icons.chevron_right,
                    size: 22,
                  ),
                ],
              ),
            ),
          ),
        ),
        Container(height: 15),
        Container(
          margin: EdgeInsets.only(left: 15, right: 15),
          child: myInkWell(
            color: os_white,
            radius: 100,
            tap: () {
              Navigator.of(context).push(CupertinoPageRoute(
                builder: (context) {
                  return UploadedTasks();
                },
              ));
            },
            widget: Container(
              padding:
                  EdgeInsets.only(left: 22.5, right: 20, top: 14, bottom: 14),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      Container(
                        decoration: BoxDecoration(
                          color: os_color_opa,
                          borderRadius: BorderRadius.circular(100),
                        ),
                        padding: EdgeInsets.all(7.5),
                        child: Icon(
                          Icons.done,
                          color: os_color,
                        ),
                      ),
                      Container(width: 12.5),
                      Text(
                        "已上传任务列表",
                        style: XSTextStyle(
                          context: context,
                          color: os_black,
                          fontSize: 15,
                          fontWeight: FontWeight.normal,
                        ),
                      ),
                    ],
                  ),
                  Icon(
                    Icons.chevron_right,
                    size: 22,
                  ),
                ],
              ),
            ),
          ),
        ),
        Container(height: 40),
        GestureDetector(
          onTap: () {},
          child: Container(
            padding: EdgeInsets.all(10),
            color: os_fake,
            child: Text(
              "@北京星美环境集团有限公司",
              style: XSTextStyle(
                context: context,
                color: os_deep_grey,
                fontSize: 15,
                fontWeight: FontWeight.normal,
              ),
            ),
          ),
        ),
        Container(height: 40),
      ],
    );
  }
}
